package cn.sjtu.java_se;

import org.junit.Test;

import java.util.Arrays;

public class TestString {

    @Test
    public void testToCharArray() {
        String test = "123456";
        char[] chs = test.toCharArray();
        System.out.println(Arrays.toString(chs));
    }

    @Test
    public void testTrim() {
        String s = "  hello world  ";
        // 1. 去除前导和后导空格
        String str = s.trim();

        // 2. 获取字符串数组
        String[] strs = s.split("\\s+");

        System.out.println(strs.length);

        // 3. StringBuilder
        StringBuilder sb = new StringBuilder();

        for (int i = strs.length - 1; i >= 0; i--) {
            sb.append(strs[i]);
        }
    }
}
